﻿using Growatt.WaveData.VirtualOscilloscope;
using System;
using System.Windows.Forms;
using Vosc;
using Vosc.VirtualOscilloscope;

namespace Growatt.Component.Frm
{
    /// <summary>
    /// 输入对话框
    /// </summary>
    public partial class FrmInputBox2 : Form
    {
        private static FrmInputBox2 frmInputBox = null;

        public FrmInputBox2()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.FrmInputBox_Load);
        }

        private void FrmInputBox_Load(object sender, EventArgs e)
        {
            //var count = MainForm.LoadConfig_ChannelCount("ConfigSaveChanelCount.ini");
            var count = 3;
            comboBox1.SelectedIndex = count;

        }

        private static Func<string, string> Func;
        private static Action<bool, (string, string, string)> FuncAddCallback;


        private string channelCount = "8";

        public string ChannelCount
        {
            get { return channelCount; }
            set { channelCount = value; }
        }

        /// <summary>
        /// 是否是输入文件名称,是则需要受到文件名称格式限制
        /// </summary>
        public bool isFileName = true;



        /// <summary>
        /// 输入值
        /// </summary>
        public string InputValue
        {
            get; set;
        }

        /// <summary>
        /// 确定按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        /// <summary>
        /// 取消按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }


        /// <summary>
        /// 输入框键盘事件 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txt_inputValue_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (isFileName) //是文件名称就需要受到格式限制
                if (e.KeyChar == ' ' || e.KeyChar == '@' || e.KeyChar == '/' || Convert.ToInt32(e.KeyChar) == 92 || e.KeyChar == '.')
                {
                    e.Handled = true;
                }
                else
                {
                    e.Handled = false;
                }
        }

        private void seletcIndex(object sender, EventArgs e)
        {
            ChannelCount = (comboBox1.SelectedIndex + 1).ToString();
            OscilloscopeControl.modelSaveChanelCount.ChanelCount = comboBox1.SelectedIndex;
        }
    }
}